// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const fs = require('fs')
const path = require('path')

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  
  try {
    // 上传图片到云存储
    const result = await cloud.uploadFile({
      cloudPath: event.cloudPath, // 云存储路径
      fileContent: Buffer.from(event.fileContent, 'base64'), // 文件内容
    })
    
    return {
      success: true,
      fileID: result.fileID,
      message: '上传成功'
    }
  } catch (error) {
    console.error(error)
    return {
      success: false,
      error: error.message
    }
  }
} 